package edu.uwosh.cs342.project4;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.StringWriter;
import java.io.Writer;
import java.lang.reflect.Array;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.List;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;


//import org.apache.commons.io.IOUtils;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.json.JSONObject;

import android.widget.Toast;
import android.os.AsyncTask;

public class DBHelper {
        private HttpPost httppost;
        private StringBuffer buffer;
        private HttpResponse response;
        private HttpClient httpclient;
        private InputStream inputStream;
        
        private List<NameValuePair> nameValuePairs;
        private byte[] data;
        private String user, pass;
        public String StringOutput;
        public String returnString;
        
        
        
        public void update(String s){       	
            URL url;
            HttpURLConnection connection = null;  
            try {
              String urlName = "http://cs346.cs.uwosh.edu/students/godinc31/sendFavs.php?data=" + s;
              url = new URL(urlName);
              connection = (HttpURLConnection)url.openConnection();

              connection.setDoOutput(false);
              connection.setDoInput(true);

              InputStream is = connection.getInputStream();//hacktivismo!

            } catch (Exception e){
              e.printStackTrace();
            }       	
        	
        }
        
        // Validate login
        public String validate(){
                try {
                        httpclient = new DefaultHttpClient();
                        httppost = new HttpPost("http://cs346.cs.uwosh.edu/students/godinc31/getFavs.php");
                        

                        /*nameValuePairs = new ArrayList<NameValuePair>(2);
                        nameValuePairs.add(new BasicNameValuePair("username",
                                        user.trim()));
                        nameValuePairs.add(new BasicNameValuePair("password",
                                        pass.trim()));
                        httppost.setEntity(new UrlEncodedFormEntity(
                                        nameValuePairs));*/

                        response = httpclient.execute(httppost);
                        inputStream = response.getEntity().getContent();

                        data = new byte[256];

                        buffer = new StringBuffer();
                        int len = 0;
                        while (-1 != (len = inputStream.read(data))) {
                                buffer.append(new String(data, 0, len));
                        }

                        inputStream.close();
                }catch (Exception e) {
                
                }
                try{
                return buffer.toString();
                }catch(NullPointerException e){
                        return "S";
                }
                
        
        }

        //      Get scores
        public String getScores(){
                return "";
        }
        
        //      Send score
        public String sendScore(){
                return "";
        }
}